package models

import (
	"time"
)

// VulnAssignmentStatus 漏洞分发状态枚举
const (
	AssignmentStatusPending     = "pending"       // 待处理
	AssignmentStatusAccepted    = "accepted"      // 已接受
	AssignmentStatusRejected    = "rejected"      // 已拒绝
	AssignmentStatusFixed       = "fixed"         // 已修复
	AssignmentStatusPendingRetest = "pending_retest" // 待复测
	AssignmentStatusClosed      = "closed"        // 已关闭
)

// VulnerabilityAssignment 漏洞分发模型
type VulnerabilityAssignment struct {
	ID              uint      `json:"id" gorm:"primary_key"`
	VulnerabilityID uint      `json:"vulnerability_id" gorm:"index"`
	AssignedToID    uint      `json:"assigned_to_id" gorm:"index"` // 分配给谁
	AssignedByID    uint      `json:"assigned_by_id"`              // 由谁分配
	Status          string    `json:"status"`                      // 状态
	Priority        int       `json:"priority"`                    // 优先级 1-5
	DueDate         time.Time `json:"due_date"`                    // 截止日期
	Notes           string    `json:"notes" gorm:"type:text"`      // 备注信息
	Response        string    `json:"response" gorm:"type:text"`   // 接收者回复
	CreatedAt       time.Time `json:"created_at"`
	UpdatedAt       time.Time `json:"updated_at"`

	// 关联
	Vulnerability Vulnerability `json:"vulnerability" gorm:"foreignkey:VulnerabilityID"`
	AssignedTo    User          `json:"assigned_to" gorm:"foreignkey:AssignedToID"`
	AssignedBy    User          `json:"assigned_by" gorm:"foreignkey:AssignedByID"`
}

// TableName 表名
func (VulnerabilityAssignment) TableName() string {
	return "vulnerability_assignments"
}

// VulnerabilityAssignmentHistory 漏洞分发历史
type VulnerabilityAssignmentHistory struct {
	ID           uint      `json:"id" gorm:"primary_key"`
	AssignmentID uint      `json:"assignment_id" gorm:"index"`
	Status       string    `json:"status"`                   // 状态变更
	Comment      string    `json:"comment" gorm:"type:text"` // 变更备注
	ChangedByID  uint      `json:"changed_by_id"`            // 变更者
	CreatedAt    time.Time `json:"created_at"`               // 变更时间

	// 关联
	Assignment VulnerabilityAssignment `json:"assignment" gorm:"foreignkey:AssignmentID"`
	ChangedBy  User                    `json:"changed_by" gorm:"foreignkey:ChangedByID"`
}

// TableName 表名
func (VulnerabilityAssignmentHistory) TableName() string {
	return "vulnerability_assignment_history"
}
